package com.gsi.webstore.platform.storefront.internal.productconfiguration;

import java.util.Collection;

import com.gsi.webstore.platform.storefront.capi.productconfiguration.ProductConfigurationBOGSIExtension;
import com.intershop.beehive.core.capi.businessobject.BusinessObject;
import com.intershop.component.productconfiguration.capi.configuration.ProductConfigurationBO;
import com.intershop.component.productconfiguration.capi.orm.set.ProductConfigurationValueTypeConstants;
import com.intershop.component.productconfiguration.capi.set.ProductConfigurationOptionBO;
import com.intershop.component.productconfiguration.capi.set.ProductConfigurationSectionBO;

/**
 * @author Martin Boehmer
 *
 */
public class ORMProductConfigurationBOGSIExtensionImpl implements ProductConfigurationBOGSIExtension
{

    private ProductConfigurationBO delegate;
    
    public ORMProductConfigurationBOGSIExtensionImpl(ProductConfigurationBO productConfiguration)
    {
        delegate = productConfiguration;
    }
    
    /* (non-Javadoc)
     * @see com.intershop.beehive.core.capi.businessobject.BusinessObjectExtension#businessObjectCreated()
     */
    @Override
    public void businessObjectCreated()
    {
    }

    /* (non-Javadoc)
     * @see com.intershop.beehive.core.capi.businessobject.BusinessObjectExtension#businessObjectDeleted()
     */
    @Override
    public void businessObjectDeleted()
    {
    }

    /* (non-Javadoc)
     * @see com.intershop.beehive.core.capi.businessobject.BusinessObjectExtension#getBusinessObject()
     */
    @Override
    public BusinessObject getBusinessObject()
    {
        return delegate;
    }

    /* (non-Javadoc)
     * @see com.gsi.webstore.platform.storefront.capi.productconfiguration.ProductConfigurationBOGSIExtension#isProductSet()
     */
    @Override
    public boolean isProductSet()
    {
        Collection<? extends ProductConfigurationSectionBO> sections = delegate.getSet().getSortedSections();
        for (ProductConfigurationSectionBO section : sections)
        {
            Collection<ProductConfigurationOptionBO> options = section.getOptions();
            for (ProductConfigurationOptionBO option : options)
            {
                if (!ProductConfigurationValueTypeConstants.ES_PRODUCT.getName().equals(option.getType()))
                {
                    return false;
                }
            }
        }        
        return true;
    }

}
